<template>
	<main-content
		:tableHeight.sync="tableHeight"
		:otherDependenComponents="otherDependenComponents"
	>
		<template slot="query">
			<el-form
				ref="queryForm"
				:inline="true"
				:model="queryData"
				label-width="auto"
				class="flex-warp-container"
			>
				<el-form-item
					:label="`${$t('common.belong_merchant')}:`"
					class="flex-row-container"
					label-width="77px"
				>
					<merchant-select
						v-model="queryData.merchantId"
						:merchantInfo.sync="currentMerchantInfo"
					></merchant-select>
				</el-form-item>
				<el-form-item
					:label="`${$t('funds.capital_adjustment.rebate_period')}:`"
					class="flex-row-container"
					label-width="103px"
				>
					<el-date-picker
						v-model="cycleStartEndDate"
						:picker-options="pickerOptionsMonth"
						format="yyyy-MM"
						type="monthrange"
						range-separator="-"
						:start-placeholder="$t('common.start_date')"
						:end-placeholder="$t('common.end_date')"
						:clearable="false"
					></el-date-picker>
				</el-form-item>
				<el-form-item
					:label="`${$t('funds.proxy_name')}:`"
					class="flex-row-container"
					label-width="77px"
				>
					<el-input
						v-model.trim="queryData.proxyName"
						clearable
						size="medium"
						v-input="{ name: 'num_alp' }"
						style="width: 200px"
						:placeholder="$t('common.please_enter')"
					></el-input>
				</el-form-item>

				<el-form-item
					:label="
						`${$t(
							'funds.capital_adjustment.parent_proxy_account'
						)}:`
					"
					class="flex-row-container"
					label-width="77px"
				>
					<el-input
						v-model.trim="queryData.parentProxyName"
						size="medium"
						style="width: 200px"
						:placeholder="$t('common.please_enter')"
						clearable
						v-input="{ name: 'num_alp' }"
					></el-input>
				</el-form-item>
				<el-form-item
					:label="`${$t('funds.capital_adjustment.lock_account')}:`"
					prop="lockAccount"
					class="flex-row-container"
					label-width="77px"
				>
					<el-input
						v-model="queryData.mixRemainingDebtAmount"
						:placeholder="$t('common.minimum')"
						style="width: 150px"
						size="medium"
						clearable
						:controls="false"
						maxLength="15"
						name="mixRemainingDebtAmount"
						v-input="{ name: 'float', num: '2' }"
						@blur="
							handleAmount(
								queryData,
								1,
								'mixRemainingDebtAmount',
								'maxRemainingDebtAmount',
								$t('funds.capital_adjustment.lock_account_tip1')
							)
						"
					></el-input>
					-
					<el-input
						v-model="queryData.maxRemainingDebtAmount"
						:placeholder="$t('common.maximum')"
						style="width: 150px"
						size="medium"
						clearable
						:controls="false"
						maxLength="15"
						name="maxRemainingDebtAmount"
						v-input="{ name: 'float', num: '2' }"
						@blur="
							handleAmount(
								queryData,
								2,
								'mixRemainingDebtAmount',
								'maxRemainingDebtAmount',
								$t('funds.capital_adjustment.lock_account_tip2')
							)
						"
					></el-input>
				</el-form-item>
				<el-form-item
					:label="
						`${$t('funds.capital_adjustment.not_recvied_amount')}:`
					"
					prop="lockAccount"
					class="flex-row-container"
					label-width="77px"
				>
					<el-input
						v-model="queryData.mixRemainingUncollectedAmount"
						:placeholder="$t('common.minimum')"
						style="width: 150px"
						size="medium"
						clearable
						:controls="false"
						maxLength="15"
						name="mixRemainingUncollectedAmount"
						v-input="{ name: 'float', num: '2' }"
						@blur="
							handleAmount(
								queryData,
								1,
								'mixRemainingUncollectedAmount',
								'maxRemainingUncollectedAmount',
								$t(
									'funds.capital_adjustment.not_recvied_amount_tip1'
								)
							)
						"
					></el-input>
					-
					<el-input
						v-model="queryData.maxRemainingUncollectedAmount"
						:placeholder="$t('common.maximum')"
						style="width: 150px"
						size="medium"
						clearable
						:controls="false"
						maxLength="15"
						name="maxRemainingUncollectedAmount"
						v-input="{ name: 'float', num: '2' }"
						@blur="
							handleAmount(
								queryData,
								2,
								'mixRemainingUncollectedAmount',
								'maxRemainingUncollectedAmount',
								$t(
									'funds.capital_adjustment.not_recvied_amount_tip2'
								)
							)
						"
					></el-input>
				</el-form-item>
				<el-form-item>
					<el-button
						type="primary"
						icon="el-icon-search"
						size="medium"
						:disabled="loading"
						@click="search"
					>
						{{ $t('common.search') }}
					</el-button>
					<el-button
						icon="el-icon-refresh-left"
						:disabled="loading"
						size="medium"
						@click="reset"
					>
						{{ $t('common.reset') }}
					</el-button>
				</el-form-item>
			</el-form>
		</template>
		<template slot="content">
			<el-table
				ref="tables"
				v-loading="loading"
				element-loading-spinner="el-icon-loading"
				border
				size="mini"
				class="small-size-table"
				:data="tableData"
				style="width: 100%"
				show-summary
				:max-height="tableHeight"
				highlight-current-row
				:header-cell-style="getRowClass"
				:summary-method="
					(val) => handleSummary(val, subSummary, totalSummary)
				"
			>
				<el-table-column
					align="center"
					:label="$t('common.actions')"
					width="180"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						<el-link
							v-if="
								hasPermission('406061') &&
									checkReplaceIssueCommission(scope.row)
							"
							type="primary"
							@click="openReplaceIssueCommission(scope.row)"
						>
							{{
								$t(
									'funds.capital_adjustment.check_commission_availability'
								)
							}}
						</el-link>
						<el-link
							v-if="
								hasPermission('406062') &&
									checkCancelCommission(scope.row)
							"
							type="primary"
							style="margin-left:10px"
							@click="openCancelCommission(scope.row)"
						>
							{{
								$t(
									'funds.capital_adjustment.check_cancel_commission_availability'
								)
							}}
						</el-link>
					</template>
				</el-table-column>
				<el-table-column
					prop="cycleName"
					width="120"
					align="center"
					:label="$t('funds.capital_adjustment.rebate_period')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{
							scope.row.cycleName ||
								getFormateDate(scope.row.reportYm, 'ym')
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="proxyName"
					align="center"
					:label="$t('funds.proxy_name')"
					width="120"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						<Copy
							v-if="scope.row.proxyName"
							:title="scope.row.proxyName"
							:copy="copy"
						>
							{{ scope.row.proxyName }}
						</Copy>
						<span v-else>-</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="accountType"
					align="center"
					:label="$t('funds.capital_adjustment.account_type')"
					width="80"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{
							typeFilter(scope.row.accountType, 'accountType') ||
								'-'
						}}
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					:label="$t('common.belong_merchant')"
					prop="merchantName"
					width="120"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ scope.row.merchantName || '-' }}
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					:label="$t('funds.capital_adjustment.proxy_level_id')"
					prop="proxyLevel"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ scope.row.proxyLevel || '-' }}
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					:label="$t('common.account_status')"
					width="120"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						<span
							v-if="scope.row.loginLockStatus === 1"
							class="disableRgba"
						>
							{{ $t('common.login_lock_status') }}
						</span>
						<span
							v-if="scope.row.paymentLockStatus === 1"
							class="deleteRgba"
						>
							{{ $t('common.account_lock_status') }}
						</span>
						<span
							v-if="
								scope.row.loginLockStatus === 0 &&
									scope.row.paymentLockStatus === 0
							"
							class="normalRgba"
						>
							{{ $t('common.account_status_normal') }}
						</span>
					</template>
				</el-table-column>
				<el-table-column
					prop="actualAmount"
					width="180"
					align="center"
					:label="
						$t(
							'funds.capital_adjustment.real_person_commission_amount'
						)
					"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ handleCurrency(scope.row.currency) }}
						{{
							handleNumber(
								scope.row.currency,
								scope.row.actualAmount
							)
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="payableAmount"
					width="180"
					align="center"
					:label="
						$t(
							'funds.capital_adjustment.total_child_commission_amount'
						)
					"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ handleCurrency(scope.row.currency) }}
						{{
							handleNumber(
								scope.row.currency,
								scope.row.payableAmount
							)
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="actualPayAmount"
					width="180"
					align="center"
					:label="$t('funds.capital_adjustment.real_pay_amount')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ handleCurrency(scope.row.currency) }}
						{{
							handleNumber(
								scope.row.currency,
								scope.row.actualPayAmount
							)
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="remainingDebtAmount"
					width="180"
					align="center"
					:label="$t('funds.capital_adjustment.lock_account')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						<span>
							{{ handleCurrency(scope.row.currency) }}
							{{
								handleNumber(
									scope.row.currency,
									scope.row.remainingDebtAmount
								)
							}}
						</span>
						<!-- <span :style="scope.row.notPayAmount && 'color:red'">
								{{ handleCurrency(scope.row.currency) }}
								{{ handleNumber(scope.row.currency, scope.row.notPayAmount) }}
							</span> -->
					</template>
				</el-table-column>
				<el-table-column
					prop="parentProxyName"
					align="center"
					:label="$t('funds.capital_adjustment.parent_proxy_account')"
					width="130"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ scope.row.parentProxyName || '-' }}
					</template>
				</el-table-column>
				<el-table-column
					prop="receivableAmount"
					width="180"
					align="center"
					:label="$t('funds.capital_adjustment.commission_amount')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ handleCurrency(scope.row.currency) }}
						{{
							handleNumber(
								scope.row.currency,
								scope.row.receivableAmount
							)
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="actualReceivableAmount"
					width="180"
					align="center"
					:label="$t('funds.capital_adjustment.real_receive_amount')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ handleCurrency(scope.row.currency) }}
						{{
							handleNumber(
								scope.row.currency,
								scope.row.actualReceivableAmount
							)
						}}
					</template>
				</el-table-column>
				<el-table-column
					prop="remainingUncollectedAmount"
					width="180"
					align="center"
					:label="$t('funds.capital_adjustment.not_recvied_amount')"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						<span>
							{{ handleCurrency(scope.row.currency) }}
							{{
								handleNumber(
									scope.row.currency,
									scope.row.remainingUncollectedAmount
								)
							}}
						</span>
					</template>
				</el-table-column>
			</el-table>
			<!-- 分页 -->
			<el-pagination
				:current-page.sync="pageNum"
				class="pageValue"
				background
				layout="total, sizes,prev, pager, next, jumper"
				:page-size="pageSize"
				:page-sizes="pageSizes"
				:total="total"
				:pager-count="9"
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
			></el-pagination>
		</template>
		<!-- 代发佣金 -->
		<el-dialog
			:title="
				$t('funds.capital_adjustment.check_commission_availability')
			"
			:visible.sync="issuedCommission.visible"
			class="showIsusuedCommission"
			:width="getWidth('500px', 2)"
			top="20vh"
			@close="closeReplaceIssueCommission"
		>
			<div
				v-loading="issuedCommission.loading"
				element-loading-spinner="el-icon-loading"
			>
				<el-form
					ref="issuedCommissionForm"
					:model="issuedCommission.formData"
					label-width="auto"
					:inline="false"
					:rules="issuedCommissionRules"
					size="normal"
					@submit.native.prevent
				>
					<el-form-item
						:label="
							`${$t(
								'funds.capital_adjustment.parent_proxy_account'
							)}:`
						"
					>
						<span>
							{{
								issuedCommission.formData.parentProxyName || '-'
							}}
						</span>
					</el-form-item>
					<el-form-item
						:label="`${$t('report.center_wallet_balance')}:`"
					>
						<span>
							{{
								handleNumber(
									issuedCommission.formData.currency,
									issuedCommission.formData.walletBalance
								)
							}}
						</span>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.capital_adjustment.in_proxy_account'
							)}:`
						"
					>
						<span>
							{{ issuedCommission.formData.proxyName || '-' }}
						</span>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.capital_adjustment.wait_issue_commission_balance'
							)}:`
						"
					>
						<span>
							{{
								issuedCommission.formData
									.remainingUncollectedAmountText
							}}
						</span>
					</el-form-item>
					<el-form-item
						:label="
							`${$t('funds.capital_adjustment.trans_amount')}:`
						"
						prop="transAmount"
					>
						<div class="currency-amount">
							<el-input
								v-model="issuedCommission.formData.transAmount"
								:placeholder="$t('common.please_enter')"
								size="medium"
								style="width:82%"
								v-input="{ name: 'float', num: '2' }"
								@input="onCheckTransAmount"
							></el-input>
							<span>
								<el-link
									type="primary"
									:underline="false"
									@click="allParentCommissionBalanceIn()"
								>
									{{
										$t('funds.capital_adjustment.all_into')
									}}
								</el-link>
							</span>
						</div>
					</el-form-item>
					<el-form-item
						:label="`${$t('funds.capital_adjustment.desc')}:`"
						prop="desc"
					>
						<el-input
							v-model.trim="issuedCommission.formData.desc"
							type="textarea"
							:maxlength="500"
							show-word-limit
							style="width:82%"
							v-input="{ name: 'noEmpty' }"
							rows="3"
						></el-input>
					</el-form-item>
				</el-form>
				<span slot="footer" class="flex-center">
					<el-button
						:disabled="issuedCommission.loading"
						@click="closeReplaceIssueCommission"
					>
						{{ $t('common.cancel') }}
					</el-button>
					<el-button
						type="primary"
						:disabled="issuedCommission.loading"
						:loading="issuedCommission.loading"
						@click="submitReplaceIssueCommission"
					>
						<span>{{ $t('common.confirm') }}</span>
					</el-button>
				</span>
			</div>
		</el-dialog>

		<!-- 取消佣金 -->
		<el-dialog
			:title="
				$t(
					'funds.capital_adjustment.check_cancel_commission_availability'
				)
			"
			:visible.sync="cancelCommission.visible"
			:width="getWidth('500px', 2)"
			top="20vh"
			@close="closeCancelCommission"
		>
			<el-form
				ref="cancelForm"
				:model="cancelCommission.formData"
				label-width="auto"
				:inline="false"
				size="normal"
				:rules="cancelCommissionRules"
			>
				<el-form-item
					:label="`${$t('funds.proxy_name')}:`"
					class="is-required"
				>
					{{ cancelCommission.formData.proxyName || '-' }}
				</el-form-item>
				<el-form-item
					:label="
						`${$t('funds.thirdPeymentChannelConfig.remark_info')}:`
					"
					prop="desc"
				>
					<el-input
						v-model.trim="cancelCommission.formData.desc"
						type="textarea"
						:maxlength="500"
						show-word-limit
						style="width:80%"
						v-input="{ name: 'noEmpty' }"
						rows="3"
					></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="flex-center">
				<el-button
					:disabled="cancelCommission.loading"
					@click="closeCancelCommission"
				>
					{{ $t('common.cancel') }}
				</el-button>
				<el-button
					:disabled="cancelCommission.loading"
					:loading="cancelCommission.loading"
					type="primary"
					@click="submitCancelCommission"
				>
					<span>{{ $t('common.confirm') }}</span>
				</el-button>
			</span>
		</el-dialog>
	</main-content>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { Decimal } from 'decimal.js'
import { routerNames } from '@/utils/consts'
import summaryList from './components/summaryList'
import MainContent from '@/components/MainContent/index.vue'
const start = dayjs()
	.startOf('month')
	.subtract(3, 'month')
const end = dayjs().endOf('month')

export default {
	name: routerNames.agentCommissionCheck,
	components: {
		MainContent
	},
	mixins: [list, summaryList],
	data() {
		return {
			tableHeight: 480,
			otherDependenComponents: [],
			cycleStartEndDate: [start, end],
			queryData: {
				merchantId: undefined,
				proxyName: undefined,
				parentProxyName: undefined,
				mixRemainingDebtAmount: undefined,
				maxRemainingDebtAmount: undefined,
				mixRemainingUncollectedAmount: undefined,
				maxRemainingUncollectedAmount: undefined,
				orderKey: undefined,
				orderType: undefined
			},
			// 代发
			issuedCommission: {
				visible: false,
				loading: false,
				formData: {
					id: undefined,
					reportYm: undefined,
					parentProxyName: undefined,
					walletBalance: undefined,
					proxyName: undefined,
					remainingUncollectedAmount: undefined,
					remainingUncollectedAmountText: undefined,
					transAmount: undefined,
					desc: undefined,
					parentCommissionBalance: 0
				}
			},
			// 取消
			cancelCommission: {
				visible: false,
				loading: false,
				formData: {
					id: undefined,
					proxyName: undefined,
					proxyId: undefined,
					desc: undefined
				}
			},
			tableData: [],
			subSummary: {},
			totalSummary: {},
			currentMerchantInfo: {}
		}
	},
	computed: {
		issuedCommissionRules() {
			const testTransAmount = (rule, value, callback) => {
				if (value === '' || value === undefined) {
					callback(
						new Error(
							this.$t('funds.capital_adjustment.form_rules_tip19')
						)
					)
				} else if (Number(value) <= 0) {
					callback(new Error('转入佣金>0'))
				} else {
					callback()
				}
			}
			return {
				transAmount: [
					{
						required: true,
						trigger: ['blur', 'change'],
						validator: testTransAmount
					}
				],
				// parentProxyName: [
				// 	{ required: true, message: '直属上级不能为空', trigger: 'blur' }
				// ],
				parentCommissionBalance: [
					{
						required: true,
						message: this.$t(
							'funds.capital_adjustment.form_rules_tip20'
						),
						trigger: ['change']
					}
				],
				proxyName: [
					{
						required: true,
						message: this.$t(
							'funds.capital_adjustment.form_rules_tip21'
						),
						trigger: 'blur'
					}
				],
				desc: [
					{
						required: true,
						message: this.$t(
							'funds.capital_adjustment.form_rules_tip23'
						),
						trigger: 'blur'
					},
					{
						min: 2,
						max: 500,
						message: '请输入2-500个字符',
						trigger: 'blur'
					}
				]
			}
		},
		cancelCommissionRules() {
			return {
				desc: [
					{
						required: true,
						message: this.$t(
							'funds.capital_adjustment.form_rules_tip25'
						),
						trigger: 'blur'
					},
					{
						min: 2,
						max: 500,
						message: '请输入2-500个字符',
						trigger: 'blur'
					}
				]
			}
		}
	},
	watch: {
		// 'issuedCommission.formData.parentCommissionBalance'(newVal) {
		// 	if (
		// 		Number(newVal) <
		// 		Number(this.issuedCommission.formData.transAmount)
		// 	) {
		// 		this.issuedCommission.formData.transAmount = Number(
		// 			this.issuedCommission.formData.parentCommissionBalance
		// 		)
		// 	}
		// }
		// 'queryData.mixRemainingDebtAmount'() {
		// 	if (
		// 		this.queryData.mixRemainingDebtAmount > this.queryData.maxRemainingDebtAmount
		// 	) {
		// 		this.queryData.maxRemainingDebtAmount =
		// 			this.queryData.mixRemainingDebtAmount + 0.01
		// 	}
		// },
		// 'queryData.mixRemainingUncollectedAmount'() {
		// 	if (
		// 		this.queryData.mixRemainingUncollectedAmount >
		// 		this.queryData.maxRemainingUncollectedAmount
		// 	) {
		// 		this.queryData.maxRemainingUncollectedAmount =
		// 			this.queryData.mixRemainingUncollectedAmount + 0.01
		// 	}
		// }
	},
	created() {},
	methods: {
		onCheckTransAmount() {
			if (this.issuedCommission.formData.transAmount !== undefined) {
				if (
					Number(this.issuedCommission.formData.transAmount) >
					Number(
						this.issuedCommission.formData
							.remainingUncollectedAmount
					)
				) {
					this.issuedCommission.formData.transAmount = Number(
						this.issuedCommission.formData
							.remainingUncollectedAmount
					)
				}
			}
		},
		async loadData() {
			this.tableData = []
			this.loading = true
			const timeArr = this.cycleStartEndDate || []
			const params = {
				...this.getParams(),
				...this.queryData,
				cycleStartDate: timeArr[0]
					? dayjs(timeArr[0])
							.startOf('month')
							.format('YYYYMMDD')
					: undefined,
				cycleEndDate: timeArr[1]
					? dayjs(timeArr[1])
							.endOf('month')
							.format('YYYYMMDD')
					: undefined
			}
			// this.pageCurrency = this.currentMerchantInfo?.currency || ''
			await this.$api
				.getNotTopProxyFundAdjustmentCommissionList(params)
				.then((res) => {
					const { record, totalRecord, summary } = res.data || {}
					this.tableData = record || []
					this.total = totalRecord || 0
					this.totalSummary = summary || {}
					this.subSummary = summary?.currentSum || {}
					this.loading = false
				})
				.catch(() => {
					this.loading = false
				})
			// this.$api
			// 	.getNonGeneralCommissionTotalSummary(params)
			// 	.then((res) => {
			// 		this.totalSummary = res?.data || {}
			// 		this.loading = false
			// 	})
			// 	.catch(() => {
			// 		this.loading = false
			// 	})
		},
		reset() {
			this.currentMerchantInfo = {}
			this.cycleStartEndDate = [start, end]
			this.queryData = {
				merchantId: undefined,
				proxyName: undefined,
				parentProxyName: undefined,
				mixRemainingDebtAmount: undefined,
				maxRemainingDebtAmount: undefined,
				mixRemainingUncollectedAmount: undefined,
				maxRemainingUncollectedAmount: undefined
			}
			this.pageNum = 1
			this.loadData()
		},

		// 排序方式(1-实际收益 2-应付佣金 3-实付佣金 4.剩余欠款 5-应收佣金 6-实收佣金 7-剩余未收
		_changeTableSort({ column, prop, order }) {
			// const keyMap = new Map([
			// 	['realPersonCommissionAmount', 1],
			// 	['totalChildCommissionAmount', 2],
			// 	['realPayAmount', 3],
			// 	['notPayAmount', 4],
			// 	['commissionAmount', 5],
			// 	['realReceiveAmount', 6],
			// 	['notRecviedAmount', 7]
			// ])
			// this.pageNum = 1
			// this.queryData.orderKey = order ? keyMap.get(prop) : undefined
			// order === 'ascending' && (this.queryData.orderType = 'asc')
			// order === 'descending' && (this.queryData.orderType = 'desc')
			// !order && (this.queryData.orderType = undefined)
			// this.loadData()
		},
		// 检测是否可以取消佣金
		checkCancelCommission(rowData) {
			if (!this.hasPermission('406062')) return false
			return true
			// if (rowData.commissionAmount !== 0 && rowData.cancelFlag !== 1) {
			// 	return true
			// } else {
			// 	return false
			// }
		},
		// 检测是否可以代发佣金
		checkReplaceIssueCommission(rowData) {
			if (!this.hasPermission('406061')) return false
			return true
			// if (rowData.notRecviedAmount !== 0) {
			// 	return true
			// } else {
			// 	return false
			// }
		},
		// 关闭代发佣金窗口
		closeReplaceIssueCommission() {
			this.issuedCommission.visible = false
			this.$refs.issuedCommissionForm.resetFields()
			this.issuedCommission.formData.parentCommissionBalance = 0
		},
		// 全部转入
		allParentCommissionBalanceIn() {
			this.issuedCommission.formData.transAmount = this.issuedCommission.formData.remainingUncollectedAmount
		},
		// 打开代发佣金
		openReplaceIssueCommission(rowData) {
			this.issuedCommission = {
				visible: true,
				loading: true,
				formData: {
					id: rowData.id,
					merchantId: rowData.merchantId,
					reportYm: rowData.reportYm,
					currency: rowData.currency,
					parentProxyName: rowData.parentProxyName,
					proxyName: rowData.proxyName,
					proxyId: rowData.proxyId,
					parentProxyId: rowData.parentProxyId,
					remainingUncollectedAmount: rowData.remainingUncollectedAmount
						? parseFloat(
								new Decimal(
									rowData.remainingUncollectedAmount
								).toFixed(2, Decimal.ROUND_DOWN)
						  )
						: 0, // 待发放返佣金额, 列表里的剩余未发
					transAmount: rowData.transAmount,
					desc: rowData.desc,
					parentCommissionBalance:
						rowData.parentCommissionBalance || 0
				}
			}
			// 金额展示处理
			this.issuedCommission.formData.remainingUncollectedAmountText = this.handleNumber(
				this.issuedCommission.formData.currency,
				this.issuedCommission.formData.remainingUncollectedAmount
			)
			// 获取中心钱包余额
			// 商户号 - merchantId
			// 直属代理id - proxyId
			this.issuedCommission.formData.walletBalance = 0
			this.$api
				.getMemberBalance({
					walletType: 17, // 中心钱包
					merchantId: this.issuedCommission.formData.merchantId,
					userName: this.issuedCommission.formData.parentProxyName
				})
				.then((res) => {
					this.issuedCommission.formData.walletBalance =
						res?.data?.balance || 0
					this.issuedCommission.loading = false
				})
				.catch(() => {
					this.issuedCommission.loading = false
				})
		},
		// 提交代发佣金
		submitReplaceIssueCommission() {
			this.$refs.issuedCommissionForm.validate((valid) => {
				if (valid) {
					if (
						Number(this.issuedCommission.formData.transAmount) >
						Number(
							this.issuedCommission.formData
								.remainingUncollectedAmount
						)
					) {
						return this.$message.error(
							'转入佣金不能大于待发放返佣金额'
						)
					}
					if (
						Number(this.issuedCommission.formData.walletBalance) <=
						0
					) {
						this.$message.closeAll()
						return this.$message.error('直属上级现金余额不足')
					}
					this.issuedCommission.loading = true
					const params = {
						id: this.issuedCommission.formData.id,
						operateType: 1, // 1-佣金发放
						reportYm: this.issuedCommission.formData.reportYm,
						transoutProyId: this.issuedCommission.formData
							.parentProxyId, // 转出代理
						transinProxyId: this.issuedCommission.formData.proxyId, // 转入代理
						transAmount: this.issuedCommission.formData.transAmount, // 转出额度
						desc: this.issuedCommission.formData.desc
					}
					this.$api
						.setNotTopProxyReplaceIssueCommission(params)
						.then((res) => {
							this.$message.success(
								this.$t('funds.capital_adjustment.success_tip')
							)
							this.issuedCommission.visible = false
							this.issuedCommission.loading = false
							this.loadData()
						})
						.catch(() => {
							this.issuedCommission.loading = false
						})
				}
			})
		},
		// 关闭取消佣金
		closeCancelCommission() {
			this.cancelCommission.visible = false
			this.cancelCommission.formData.desc = undefined
		},
		// 打开取消佣金
		openCancelCommission(rowData) {
			this.cancelCommission.visible = true
			this.cancelCommission.formData.id = rowData.id
			this.cancelCommission.formData.reportYm = rowData.reportYm
			this.cancelCommission.formData.proxyId = rowData.proxyId
			this.cancelCommission.formData.proxyName = rowData.proxyName
			this.cancelCommission.formData.desc = undefined
		},
		// 提交取消佣金
		async submitCancelCommission() {
			this.$refs.cancelForm.validate((valid) => {
				if (!valid) {
					return false
				}
				this.cancelCommission.loading = true
				const params = {
					// id: this.cancelCommission.formData.id,
					// adjustType: 1,
					proxyId: this.cancelCommission.formData.proxyId,
					auditDesc: this.cancelCommission.formData.desc,
					cycleStartDate: dayjs(
						String(this.cancelCommission.formData.reportYm)
					)
						.startOf('month')
						.format('YYYYMMDD'),
					cycleEndDate: dayjs(
						String(this.cancelCommission.formData.reportYm)
					)
						.endOf('month')
						.format('YYYYMMDD')
				}
				this.$api
					.cancelProxySettlementCommission(params)
					.then((res) => {
						this.cancelCommission.loading = false
						if (res?.code === 200) {
							this.cancelCommission.visible = false
							this.$message.success(
								this.$t('funds.capital_adjustment.cancel_tip1')
							)
							this.loadData()
						}
					})
					.catch(() => {
						this.cancelCommission.visible = false
						this.cancelCommission.loading = false
					})
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.currency-amount {
	::v-deep .el-input__inner {
		padding-left: 25px;
	}
}
.currency-sign {
	position: absolute;
	left: 8px;
	z-index: 5;
}
::v-deep .el-dialog__header {
	color: #5c5c5c;
	font-weight: 700;
	border-bottom: 1px solid #00000015;
}
.params {
	padding-bottom: 15px;
}
.line {
	border-bottom: 1px solid #00000015;
	margin-bottom: 30px;
}
.showIsusuedCommission {
	::v-deep .el-input__inner {
		text-align: left;
	}
}
::v-deep .footer_count_row {
	min-height: 50px;
	height: 50%;
	display: flex;
	font-weight: 700;
	padding: 5px 0;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
::v-deep .footer_count_row_border {
	border-top: 1px solid #ebeef5;
}
</style>
